From 44c760d148b712a805261c2480944c9e092ffcf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Davidovi=C4=87?= Date: Wed, 24 Dec 2014 21:37:01 +0100 Subject: [PATCH] Avoid logic duplication As suggested by @alexcrichton, reverted back to the old way of handling both Job::new and Job::noop that avoids ugly constructs and code duplication --- src/cargo/ops/cargo_rustc/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index fb61306e6..5029b8a6b 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -201,6 +201,12 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, // a real job. Packages which are *not* compiled still have their jobs // executed, but only if the work is fresh. This is to preserve their // artifacts if any exist. + let job = if compiled { + Job::new as fn(Work, Work) -> Job + } else { + Job::noop as fn(Work, Work) -> Job + }; + if !compiled { jobs.ignore(pkg); } if targets.is_empty() { @@ -252,8 +258,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, try!(work.call(desc_tx.clone())); dirty.call(desc_tx) }); - dst.push((if compiled { Job::new(dirty, fresh) } - else { Job::noop(dirty, fresh) }, freshness)); + dst.push((job(dirty, fresh), freshness)); } // If this is a custom build command, we need to not only build the @@ -290,8 +295,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, } let (dirty, fresh, freshness) = try!(custom_build::prepare(pkg, target, req, cx)); - run_custom.push((if compiled { Job::new(dirty, fresh) } - else { Job::noop(dirty, fresh) }, freshness)); + run_custom.push((job(dirty, fresh), freshness)); } // If no build scripts were run, no need to compile the build script! @@ -330,8 +334,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, dirty.call(desc_tx) }); jobs.enqueue(pkg, Stage::BuildCustomBuild, vec![]); - jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(if compiled { Job::new(dirty, fresh) } - else { Job::noop(dirty, fresh) }, freshness)]); + jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(job(dirty, fresh), freshness)]); } jobs.enqueue(pkg, Stage::Libraries, libs); -- 2.30.2